package com.hlbb.dao;


import java.util.List;

import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import static org.hibernate.criterion.Example.create;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.hlbb.domain.bean.Camaster;
import com.hlbb.domain.bean.CamasterId;


/**
 * A data access object (DAO) providing persistence and search support for
 * Camaster entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.hlbbackend.domain.bean.Camaster
 * @author MyEclipse Persistence Tools
 */
@Repository("camasterDAO")
public class CamasterDAO extends BaseHelperDAO {
	private static final Logger log = LoggerFactory
			.getLogger(CamasterDAO.class);
	// property constants
	public static final String LASTSTATEMENTDATE = "laststatementdate";
	public static final String CUSTOMERNAME = "customername";
	public static final String ADDRESSLINE1 = "addressline1";
	public static final String ADDRESSLINE2 = "addressline2";
	public static final String ADDRESSLINE3 = "addressline3";
	public static final String ADDRESSLINE4 = "addressline4";
	public static final String ADDRESSLINE5 = "addressline5";
	public static final String BRANCHID = "branchid";
	public static final String BRANCHNUMBER = "branchnumber";
	public static final String BRANCHNAME = "branchname";
	public static final String TELEPHONENUMBER = "telephonenumber";
	public static final String ACCOUNTSTATUS = "accountstatus";
	public static final String LEDGERBALANCE = "ledgerbalance";
	public static final String NEGATIVEMASK = "negativemask";
	public static final String CURRENCYCODE = "currencycode";
	public static final String NUMBEROCREDIT = "numberocredit";
	public static final String AMOUNTOFCREDIT = "amountofcredit";
	public static final String NUMBEROFDEBIT = "numberofdebit";
	public static final String AMOUNTOFDEBIT = "amountofdebit";
	public static final String TOTALAMOUNT = "totalamount";
	public static final String TOTALCOUNT = "totalcount";
	public static final String PRODUCTCODE = "productcode";
	public static final String PRODUCTDESCRIPTION = "productdescription";
	public static final String DOB = "dob";
	public static final String ISFLAG = "isflag";
	public static final String HOLDMAIL = "holdmail";
	public static final String SUPRESSMAIL = "supressmail";
	public static final String FOREIGNADDRESS = "foreignaddress";
	public static final String POSTCODE = "postcode";
	public static final String REGIONCODE = "regioncode";
	public static final String POSTCODEFLAG = "postcodeflag";
	public static final String EMAILADDRESS = "emailaddress";
	public static final String REBATECARRYFORWARD = "rebatecarryforward";
	public static final String REBATEEARN = "rebateearn";
	public static final String REBATEREDEEM = "rebateredeem";
	public static final String REBATEOUTSTANDING = "rebateoutstanding";
	public static final String REBATESEXPIRYDATE = "rebatesexpirydate";
	public static final String COMBINESTATEMENT = "combinestatement";
	public static final String PROIRITYORPRIVATE = "proirityorprivate";
	public static final String MSCLASS = "msclass";
	public static final String MACHPRODUCT = "machproduct";
	public static final String SHAREPRODUCT = "shareproduct";
	public static final String HONGLEONGONEACCOUNT = "hongleongoneaccount";
	public static final String PAYROLLACCOUNT = "payrollaccount";
	public static final String _ESTATEMENT = "EStatement";
	public static final String HLB_STAFF = "hlbStaff";
	public static final String FILLER = "filler";

	public void save(Camaster transientInstance) {
		log.debug("saving Camaster instance");
		try {
			getCurrentSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Camaster persistentInstance) {
		log.debug("deleting Camaster instance");
		try {
			getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Camaster findById(CamasterId id) {
		log.debug("getting Camaster instance with id: " + id);
		try {
			Camaster instance = (Camaster) getCurrentSession().get(
					"com.hlbbackend.domain.bean.Camaster", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<Camaster> findByExample(Camaster instance) {
		log.debug("finding Camaster instance by example");
		try {
			List<Camaster> results = (List<Camaster>) getCurrentSession()
					.createCriteria("com.hlbbackend.domain.bean.Camaster")
					.add(create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Camaster instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Camaster as model where model."
					+ propertyName + "= ?";
			Query queryObject = getCurrentSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<Camaster> findByLaststatementdate(Object laststatementdate) {
		return findByProperty(LASTSTATEMENTDATE, laststatementdate);
	}

	public List<Camaster> findByCustomername(Object customername) {
		return findByProperty(CUSTOMERNAME, customername);
	}

	public List<Camaster> findByAddressline1(Object addressline1) {
		return findByProperty(ADDRESSLINE1, addressline1);
	}

	public List<Camaster> findByAddressline2(Object addressline2) {
		return findByProperty(ADDRESSLINE2, addressline2);
	}

	public List<Camaster> findByAddressline3(Object addressline3) {
		return findByProperty(ADDRESSLINE3, addressline3);
	}

	public List<Camaster> findByAddressline4(Object addressline4) {
		return findByProperty(ADDRESSLINE4, addressline4);
	}

	public List<Camaster> findByAddressline5(Object addressline5) {
		return findByProperty(ADDRESSLINE5, addressline5);
	}

	public List<Camaster> findByBranchid(Object branchid) {
		return findByProperty(BRANCHID, branchid);
	}

	public List<Camaster> findByBranchnumber(Object branchnumber) {
		return findByProperty(BRANCHNUMBER, branchnumber);
	}

	public List<Camaster> findByBranchname(Object branchname) {
		return findByProperty(BRANCHNAME, branchname);
	}

	public List<Camaster> findByTelephonenumber(Object telephonenumber) {
		return findByProperty(TELEPHONENUMBER, telephonenumber);
	}

	public List<Camaster> findByAccountstatus(Object accountstatus) {
		return findByProperty(ACCOUNTSTATUS, accountstatus);
	}

	public List<Camaster> findByLedgerbalance(Object ledgerbalance) {
		return findByProperty(LEDGERBALANCE, ledgerbalance);
	}

	public List<Camaster> findByNegativemask(Object negativemask) {
		return findByProperty(NEGATIVEMASK, negativemask);
	}

	public List<Camaster> findByCurrencycode(Object currencycode) {
		return findByProperty(CURRENCYCODE, currencycode);
	}

	public List<Camaster> findByNumberocredit(Object numberocredit) {
		return findByProperty(NUMBEROCREDIT, numberocredit);
	}

	public List<Camaster> findByAmountofcredit(Object amountofcredit) {
		return findByProperty(AMOUNTOFCREDIT, amountofcredit);
	}

	public List<Camaster> findByNumberofdebit(Object numberofdebit) {
		return findByProperty(NUMBEROFDEBIT, numberofdebit);
	}

	public List<Camaster> findByAmountofdebit(Object amountofdebit) {
		return findByProperty(AMOUNTOFDEBIT, amountofdebit);
	}

	public List<Camaster> findByTotalamount(Object totalamount) {
		return findByProperty(TOTALAMOUNT, totalamount);
	}

	public List<Camaster> findByTotalcount(Object totalcount) {
		return findByProperty(TOTALCOUNT, totalcount);
	}

	public List<Camaster> findByProductcode(Object productcode) {
		return findByProperty(PRODUCTCODE, productcode);
	}

	public List<Camaster> findByProductdescription(Object productdescription) {
		return findByProperty(PRODUCTDESCRIPTION, productdescription);
	}

	public List<Camaster> findByDob(Object dob) {
		return findByProperty(DOB, dob);
	}

	public List<Camaster> findByIsflag(Object isflag) {
		return findByProperty(ISFLAG, isflag);
	}

	public List<Camaster> findByHoldmail(Object holdmail) {
		return findByProperty(HOLDMAIL, holdmail);
	}

	public List<Camaster> findBySupressmail(Object supressmail) {
		return findByProperty(SUPRESSMAIL, supressmail);
	}

	public List<Camaster> findByForeignaddress(Object foreignaddress) {
		return findByProperty(FOREIGNADDRESS, foreignaddress);
	}

	public List<Camaster> findByPostcode(Object postcode) {
		return findByProperty(POSTCODE, postcode);
	}

	public List<Camaster> findByRegioncode(Object regioncode) {
		return findByProperty(REGIONCODE, regioncode);
	}

	public List<Camaster> findByPostcodeflag(Object postcodeflag) {
		return findByProperty(POSTCODEFLAG, postcodeflag);
	}

	public List<Camaster> findByEmailaddress(Object emailaddress) {
		return findByProperty(EMAILADDRESS, emailaddress);
	}

	public List<Camaster> findByRebatecarryforward(Object rebatecarryforward) {
		return findByProperty(REBATECARRYFORWARD, rebatecarryforward);
	}

	public List<Camaster> findByRebateearn(Object rebateearn) {
		return findByProperty(REBATEEARN, rebateearn);
	}

	public List<Camaster> findByRebateredeem(Object rebateredeem) {
		return findByProperty(REBATEREDEEM, rebateredeem);
	}

	public List<Camaster> findByRebateoutstanding(Object rebateoutstanding) {
		return findByProperty(REBATEOUTSTANDING, rebateoutstanding);
	}

	public List<Camaster> findByRebatesexpirydate(Object rebatesexpirydate) {
		return findByProperty(REBATESEXPIRYDATE, rebatesexpirydate);
	}

	public List<Camaster> findByCombinestatement(Object combinestatement) {
		return findByProperty(COMBINESTATEMENT, combinestatement);
	}

	public List<Camaster> findByProirityorprivate(Object proirityorprivate) {
		return findByProperty(PROIRITYORPRIVATE, proirityorprivate);
	}

	public List<Camaster> findByMsclass(Object msclass) {
		return findByProperty(MSCLASS, msclass);
	}

	public List<Camaster> findByMachproduct(Object machproduct) {
		return findByProperty(MACHPRODUCT, machproduct);
	}

	public List<Camaster> findByShareproduct(Object shareproduct) {
		return findByProperty(SHAREPRODUCT, shareproduct);
	}

	public List<Camaster> findByHongleongoneaccount(Object hongleongoneaccount) {
		return findByProperty(HONGLEONGONEACCOUNT, hongleongoneaccount);
	}

	public List<Camaster> findByPayrollaccount(Object payrollaccount) {
		return findByProperty(PAYROLLACCOUNT, payrollaccount);
	}

	public List<Camaster> findByEStatement(Object EStatement) {
		return findByProperty(_ESTATEMENT, EStatement);
	}

	public List<Camaster> findByHlbStaff(Object hlbStaff) {
		return findByProperty(HLB_STAFF, hlbStaff);
	}

	public List<Camaster> findByFiller(Object filler) {
		return findByProperty(FILLER, filler);
	}

	public List findAll() {
		log.debug("finding all Camaster instances");
		try {
			String queryString = "from Camaster";
			Query queryObject = getCurrentSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Camaster merge(Camaster detachedInstance) {
		log.debug("merging Camaster instance");
		try {
			Camaster result = (Camaster) getCurrentSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Camaster instance) {
		log.debug("attaching dirty Camaster instance");
		try {
			getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Camaster instance) {
		log.debug("attaching clean Camaster instance");
		try {
			getCurrentSession().buildLockRequest(LockOptions.NONE).lock(
					instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CamasterDAO getFromApplicationContext(ApplicationContext ctx) {
		return (CamasterDAO) ctx.getBean("CamasterDAO");
	}
}